import React,{Component} from 'react';
import './home.css';
import {queryAll} from "../../api/news";
import Cell from "../../components/cell";
import UcSwiper from "../../components/uc-swiper/uc-swiper";

export default class Home extends Component {

  state = {
    home:[],
    banner:[]
  };

  async componentDidMount(){
    let [{data:home},{data:banner}] = await queryAll();
    banner.map(item=>item.url=`/detail/${item._id}?collectionName=banner`)
    this.setState({home,banner});
  }
  render(){
    let {home,banner} = this.state;
    return (
      <div>

        <UcSwiper autoplay data={banner}/>

        {
          home.map((item,index)=>(
            <Cell
              key={item._id}
              title={(index + 1) + '. ' + item.title}
              label={item.des}
              to={`/detail/${item._id}?collectionName=home`}/>
          ))
        }
      </div>
    )
  }
}